package org.myblog.myblogserver.code.controller;

import org.myblog.myblogserver.code.entity.People;
import org.myblog.myblogserver.code.service.PeopleService;
import org.myblog.myblogserver.dao.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;

@Api(tags = "People")
@RestController
@RequestMapping("/people")
public class PeopleController {

    @Autowired
    private PeopleService peopleService;

    private Result result = new Result();

    /**
     * get  /select/select<br/>
     *
     * @author 智哥
     * @return Result
     * */
    @ApiOperation(value = "People查询")
    @GetMapping("/select")
    public Result select() {
        if(peopleService.getById(1) != null){
            result.success("查询成功", peopleService.list());
        }else {
            result.client_fail("查询失败", null);
        }
        return result;
    }


    /**
     * get  /select/update<br/>
     *
     * @author 智哥
     * @return Result
     * */
    @ApiOperation(value = "People修改")
    @GetMapping("/update")
    public Result update() {
        People p=peopleService.getById(1);
        p.setNum(p.getNum()+1);
        if(peopleService.updateById(p)){
            result.success("修改成功", null);
        }else {
            result.server_fail("修改失败", null);
        }
        return result;
    }


}